"""
递归定义：N! = N * (N-1)!
递归调用：一个函数直接或间接的调用了自身

练习：一个小孩爬楼梯，一次可以爬1个台阶、2个台阶或3个台阶，问爬完10个台阶有多少种走法？
"""
from functools import lru_cache, partial


# @lru_cache()
# def climb(num):
#     if num == 0:
#         return 1
#     elif num < 0:
#         return 0
#     return climb(num - 1) + climb(num - 2) + climb(num - 3)


def climb(num):
    a, b, c = 1, 2, 4
    for _ in range(num - 1):
        a, b, c = b, c, a + b + c
    return a


# for i in range(1, 11):
#     print(i, climb(i))


def fac(num):
    if num == 0:
        return 1
    return num * fac(num - 1)


# print(fac(5))


# Least Recently Used - 最近最少使用 - 缓存置换策略
@lru_cache()
def fib(num):
    if num in (1, 2):
        return 1
    return fib(num - 1) + fib(num - 2)


# for i in range(1, 121):
#     print(i, fib(i))


def add(a, b):
    return a + b


add = partial(add, 100)

print(add(1))
print(add(10))
